package com.ai.mall.controller.admin;

import com.ai.mall.entity.AddressesEntity;
import com.ai.mall.service.AddressesService;
import com.ai.mall.utils.PageUtils;
import com.ai.mall.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 地址表
 *
 * @author easue
 * @email sunlightcs@gmail.com
 * @date 2025-01-21 14:40:34
 */
@RestController
@RequestMapping("mall/addresses")
public class AddressesController {
    @Autowired
    private AddressesService addressesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("mall:addresses:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = addressesService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{addressId}")
    //@RequiresPermissions("mall:addresses:info")
    public R info(@PathVariable("addressId") Integer addressId){
		AddressesEntity addresses = addressesService.getById(addressId);

        return R.ok().put("addresses", addresses);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("mall:addresses:save")
    public R save(@RequestBody AddressesEntity addresses){
		addressesService.save(addresses);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("mall:addresses:update")
    public R update(@RequestBody AddressesEntity addresses){
		addressesService.updateById(addresses);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("mall:addresses:delete")
    public R delete(@RequestBody Integer[] addressIds){
		addressesService.removeByIds(Arrays.asList(addressIds));

        return R.ok();
    }

}
